package cn.newstrength.qiyiming.step;

import cn.newstrength.wtdf.plugin.param.TranParams;
import cn.newstrength.wtdf.plugin.result.TranResult;
import cn.newstrength.wtdf.plugin.util.SpringUtils;
import cn.newstrength.wtdf.web.databus.DataContext;
import cn.newstrength.wtdf.web.exception.PAIException;
import cn.newstrength.wtdf.web.mybatis.service.MapperService;
import cn.newstrength.wtdf.web.mybatis.service.impl.MapperServiceImpl;
import cn.newstrength.wtdf.web.processor.Operation;
import cn.newstrength.wtdf.web.processor.OperationStep;
import cn.newstrength.wtdf.web.util.StepUtils;

import java.util.Map;

public class QYMInsertStep implements OperationStep {
    @Override
    public int excute(Operation oper) throws PAIException {
        DataContext context = oper.getContext();
        String mapSet = context.getElementValue("mapSet");
        Map<String, Object> inputValue = StepUtils.getInputValue(oper, mapSet);
        String resource = context.getElementValue("resource");
        if(resource!=null&&!resource.equals("")){
            MapperService mapperService = SpringUtils.getBean("mapperService", MapperServiceImpl.class);
            TranParams<Map<String,Object>> params = new TranParams(inputValue);
            params.setResource(resource);
            params.setSummary("添加客户");
            params.setTranType("InsertStep");
            TranResult<Map<String, Object>> tranResult = mapperService.insert(params);
            oper.setTranResult(tranResult);
            return 0;
        }else {
            context.setTranStepResult(-1,"请设置查询Resource",(Object) null);
            return -1;
        }

    }

    @Override
    public int init(Map<String, String> param) {
        return 0;
    }
}

